package com.shxc.smarttrade.old.activity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.shxc.smarttrade.R;
import com.shxc.smarttrade.account.activity.AccountAboutUsActivity;
import com.shxc.smarttrade.account.activity.AccountSettingActivity;
import com.shxc.smarttrade.account.activity.HelpCenterActivity;
import com.shxc.smarttrade.login.activity.LoginHomeActivity;
import com.shxc.smarttrade.utils.AppUtils;
import com.shxc.smarttrade.old.myview.CommonDialog;
import com.shxc.smarttrade.old.utils.CloseAllActivity;
import com.shxc.smarttrade.old.utils.SpUtils;
import com.umeng.analytics.MobclickAgent;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import ch.ielse.view.SwitchView;

/**
 * Created by jcdev1 on 2017/10/29.
 */

public class SettingActivity extends BaseActivity {

    @BindView(R.id.tv_center)
    TextView tvCenter;
    @BindView(R.id.sw_sound)
    SwitchView swSound;
    @BindView(R.id.ll_quick_order)
    LinearLayout llQuickOrder;
    @BindView(R.id.tv_quick_order_status)
    TextView tvQuickOrderStatus;
    @BindView(R.id.tv_quick_close_position_status)
    TextView tvQuickClosePositionStatus;

    private boolean quickOrderStatus = false;
    private boolean quickClosePosition = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
        ButterKnife.bind(this);
        initView();
        initListener();
        initData();
    }


    private void initView() {
        tvCenter.setText("setting");
    }

    private void initListener() {
        swSound.setOnStateChangedListener(new SwitchView.OnStateChangedListener() {
            @Override
            public void toggleToOn(SwitchView view) {
                view.toggleSwitch(true); // or false
            }

            @Override
            public void toggleToOff(SwitchView view) {
                view.toggleSwitch(false); // or true
            }
        });
    }

    private void initData() {


    }

    @OnClick({R.id.rl_left, R.id.ll_title_all, R.id.ll_self_info, R.id.ll_trade_account, R.id.ll_help, R.id.ll_customer_service, R.id.ll_about_us, R.id.ll_quite, R.id.ll_quick_order, R.id.ll_quick_close_position})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.rl_left:
                finish();
                break;
            case R.id.ll_title_all:
                break;
            case R.id.ll_self_info:
//                String url="mqqwpa://im/chat?chat_type=wpa&uin=392306436";
//                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
//                startActivity(PersonInfoActivity.class);
                startActivity(AccountSettingActivity.class);
                break;
            case R.id.ll_trade_account:
                startActivity(TradeAccountActivity.class);
                break;
            case R.id.ll_help:
//                Intent intent = new Intent(this, HFiveActivity.class);
//                intent.putExtra("name", "帮助中心");
//                intent.putExtra("url", URLContents.HELP_CENTER);
//                startActivity(intent);
                Intent intent = new Intent(this, HelpCenterActivity.class);
                startActivity(intent);
                break;
            case R.id.ll_customer_service:
                AppUtils.copyText(this,"whjyds168");
                Toast.makeText(this,"复制成功",Toast.LENGTH_SHORT).show();
                break;
            case R.id.ll_about_us:
//                startActivity(AboutUsActivity.class);
                startActivity(AccountAboutUsActivity.class);
                break;
            case R.id.ll_quite:
                quitApp();
                break;
            case R.id.ll_quick_order:
                Intent intentOrder = new Intent(this, QuickOrderProtocolActivity.class);
                intentOrder.putExtra("tag", 0);
                startActivity(intentOrder);
                break;
            case R.id.ll_quick_close_position:
                Intent intentClose = new Intent(this, QuickOrderProtocolActivity.class);
                intentClose.putExtra("tag", 1);
                startActivity(intentClose);
                break;
        }
    }


    private void quitApp() {
        CommonDialog commonDialog = new CommonDialog(this, R.style.customDialogStyle);
        commonDialog.setCanceledOnTouchOutside(true);
        commonDialog.setBaseText("提示", "是否退出账号？", "取消", "确定");
        commonDialog.setYesCLickRunAble(new Runnable() {
            @Override
            public void run() {
//                finish();
                CloseAllActivity.getScreenManager().clearAllActivity();
                SharedPreferences setPreferences = getSharedPreferences(
                        "app", Context.MODE_PRIVATE);
                SharedPreferences.Editor editor = setPreferences.edit();
                editor.clear();
                editor.commit();
                SpUtils.putBoolean(SettingActivity.this, "firstOpen", false);
                startActivity(new Intent(SettingActivity.this, LoginHomeActivity.class));
                MobclickAgent.onEvent(SettingActivity.this, "login");//友盟统计该点击事件发生次数
            }
        });
        commonDialog.show();
    }

    @Override
    protected void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
        quickOrderStatus = SpUtils.getBoolean(this, "quickOrderStatus", false);
        quickClosePosition = SpUtils.getBoolean(this, "quickClosePosition", false);
        if (quickOrderStatus)
            tvQuickOrderStatus.setText("开");
        else
            tvQuickOrderStatus.setText("关");

        if (quickClosePosition)
            tvQuickClosePositionStatus.setText("开");
        else
            tvQuickClosePositionStatus.setText("关");
    }

    @Override
    protected void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

    }
}
